package cn.iocoder.yudao.module.javainfo.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@AllArgsConstructor
@Getter
public enum AmountTypeEnum {
    CONSUME(1, "CONSUME", "消费"),
    RECHARGE(2, "RECHARGE", "充值"),
    ;

    private final Integer type;
    private final String value;
    private final String desc;

    private static Map<Integer, AmountTypeEnum> cache;
    private static Map<String, AmountTypeEnum> cacheValue;

    static {
        cache = Arrays.stream(AmountTypeEnum.values()).collect(Collectors.toMap(AmountTypeEnum::getType, Function.identity()));
        cacheValue = Arrays.stream(AmountTypeEnum.values()).collect(Collectors.toMap(AmountTypeEnum::getValue, Function.identity()));
    }

    public static AmountTypeEnum of(Integer type) {
        return cache.get(type);
    }

    public static AmountTypeEnum ofValue(String value) {
        return cacheValue.get(value);
    }
}
